package com.atguigui.leetcode;

/**
 * 1759.统计同构子字符串的数目
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/12/26 9:12
 */
public class P1759CountNumberOfHomogenousSubstrings {
    public static void main(String[] args) {
        Solution solution = new P1759CountNumberOfHomogenousSubstrings().new Solution();
        // TO TEST
    }

    class Solution {
        public int countHomogenous(String s) {
            final int MOD = 1000000007;
            long res = 0;
            char prev = s.charAt(0);
            int cnt = 0;
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                if (c == prev) {
                    cnt++;
                } else {
                    //计算个数
                    res += (long) (cnt + 1) * cnt / 2;
                    cnt = 1;
                    //更新指针
                    prev = c;
                }
            }
            res += (long) (cnt + 1) * cnt / 2;
            return (int) (res % MOD);
        }
    }
}
